package com.itxinyu.src.dao.Imp;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate5.HibernateCallback;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import com.itxinyu.src.dao.LoginDao;
import com.itxinyu.src.entity.User;

public class LoginDaoImp extends HibernateDaoSupport implements LoginDao {

	@Override
	public User login(final String user_code) {
		
		return	getHibernateTemplate().execute(new HibernateCallback<User>() {

			@Override
			public User doInHibernate(Session session) throws HibernateException {
				String sqlString = "from User where user_code = ? ";
				Query query = session.createQuery(sqlString);
				query.setParameter(0, user_code);
				User uObject = (User) query.uniqueResult();
				return uObject;
			}
		});
		 
	}

}
